/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Cos;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_42896
/*     */   extends UpgradeOp
/*     */ {
/*     */   void doUpgrade()
/*     */     throws ServiceException
/*     */   {
/*  36 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  38 */       doAllCos(zlc);
/*     */     } finally {
/*  40 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   private void setZimbraMailQuotaConstraint(ZLdapContext zlc, Cos cos)
/*     */   {
/*  47 */     String quotaLimitOnCosStr = cos.getAttr("zimbraDomainAdminMaxMailQuota");
/*     */     
/*  49 */     this.printer.println("Cos " + cos.getName() + ": " + "zimbraDomainAdminMaxMailQuota" + "=" + quotaLimitOnCosStr);
/*     */     
/*  51 */     if (quotaLimitOnCosStr == null) {
/*  52 */       this.printer.println("Skip setting constraint for zimbraMailQuota on cos " + cos.getName());
/*  53 */       return;
/*     */     }
/*     */     
/*  56 */     long quotaLimitOnCos = Long.parseLong(quotaLimitOnCosStr);
/*     */     
/*     */ 
/*  59 */     if (quotaLimitOnCos == 0L) {
/*  60 */       this.printer.println("Skip setting constraint for zimbraMailQuota on cos " + cos.getName());
/*  61 */       return;
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*  66 */     if (quotaLimitOnCos == -1L) {
/*  67 */       this.printer.println("Skip setting constraint for zimbraMailQuota on cos " + cos.getName());
/*  68 */       return;
/*     */     }
/*     */     
/*  71 */     Set<String> constraints = cos.getMultiAttrSet("zimbraConstraint");
/*     */     
/*  73 */     for (String constraint : constraints) {
/*  74 */       if (constraint.startsWith("zimbraMailQuota")) {
/*  75 */         this.printer.println("Skip setting constraint for zimbraMailQuota on cos " + cos.getName() + ", it is currently set to " + constraint);
/*  76 */         return;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*  81 */     String value = "zimbraMailQuota:max=" + quotaLimitOnCos;
/*  82 */     constraints.add(value);
/*     */     
/*  84 */     Map<String, Object> newValues = new HashMap();
/*  85 */     newValues.put("zimbraConstraint", constraints.toArray(new String[constraints.size()]));
/*     */     try
/*     */     {
/*  88 */       this.printer.println("Modifying zimbraConstraint on cos " + cos.getName() + ", adding value " + value);
/*  89 */       modifyAttrs(zlc, cos, newValues);
/*     */     }
/*     */     catch (ServiceException e) {
/*  92 */       this.printer.println("Caught ServiceException while modifying zimbraConstraint attribute ");
/*  93 */       this.printer.printStackTrace(e);
/*     */     }
/*     */   }
/*     */   
/*     */   private void doAllCos(ZLdapContext zlc) throws ServiceException {
/*  98 */     List<Cos> coses = this.prov.getAllCos();
/*     */     
/* 100 */     for (Cos cos : coses) {
/* 101 */       setZimbraMailQuotaConstraint(zlc, cos);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_42896.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */